using System;
using System.Collections.Generic;
using System.Text;

namespace TST.SharePoint.Shared
{
    /// <summary>
    /// Collection that holds Field objects.
    /// </summary>
    public class Fields : FieldCollection<Field>
    {
        public Fields()
        {
        }

        /// <summary>
        /// Return a list of fields with the specified displayname. Normally this should just
        /// be 1 field, but in SharePoint there can be multiple fields with the same
        /// display name.
        /// </summary>
        /// <param name="displayname">The display name of the field(s) to be returned.</param>
        /// <returns>A list of Field objects with the specified displayname.</returns>
        public Fields GetFieldsWithDisplayName(string displayname)
        {
            Fields list = new Fields();
            foreach (Field field in this)
            {
                if (string.Compare(field.DisplayName, displayname, true) == 0)
                    list.Add(field);
            }
            return list;
        }

        public Field GetFirstFieldWithName(string name)
        {
            foreach (Field field in this)
            {
                if (string.Compare(field.Name, name, true) == 0)
                    return field;
            }
            return null;
        }

    }
}
